package core;

import session.ClientSession;
import session.ServerSession;
import session.Session;

public class App implements Runnable, AutoCloseable {
    Config config;
    Session session;

    public App(Config config) {
        this.config = config;
    }

    @Override
    public void run() {
        try {
            switch (config.getRunType()) {
                case Client: {
                    session = new ClientSession(config);
                    break;
                }
                case Server: {
                    session = new ServerSession(config);
                    break;
                }
            }
            session.run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void close() throws Exception {
        session.close();
    }
}
